﻿Imports CupsApp.Service
Imports CupsApp.Data

Partial Public Class status
    Inherits System.Web.UI.Page

    Public _service As CupsDomainService
    Public _data As ClientStatus
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim context As New HttpContextWrapper(HttpContext.Current)
        Dim _service As CupsDomainService = DomainServicesFactory.CreateDomainService(context)



        _data = New ClientStatus
        lvlMsg.Text = ""
        If Not IsPostBack Then
            If IsNothing(Request.QueryString("clientID")) Then
                CType(Master.FindControl("lnkNewClient"), LinkButton).Enabled = False
                CType(Master.FindControl("lnkNewClient"), LinkButton).Text = "> New Client/Family <"
            Else
                Client_ID.Value = Request.QueryString("clientID")

            End If
        End If
    End Sub

#Region "Click Events"

    Protected Sub lnkPersonal_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkPersonal.Click
        Response.Redirect(String.Format("personal.aspx?clientID={0}", Client_ID.Value))
    End Sub

    Protected Sub lnkBackground_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkBackground.Click
        Response.Redirect(String.Format("background.aspx?clientID={0}", Client_ID.Value))
    End Sub

    Protected Sub lnkHealthLegal_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkHealthLegal.Click
        Response.Redirect(String.Format("health_legal.aspx?clientID={0}", Client_ID.Value))
    End Sub

    Protected Sub lnkHousing_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkHousing.Click
        Response.Redirect(String.Format("housing.aspx?clientID={0}", Client_ID.Value))
    End Sub

    Protected Sub lnkFollowUp_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkFollowUp.Click
        Response.Redirect(String.Format("follow_up.aspx?clientID={0}", Client_ID.Value))
    End Sub

    Protected Sub lnkExit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles lnkExit.Click
        Response.Redirect(String.Format("exit.aspx?clientID={0}", Client_ID.Value))
    End Sub

#End Region

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
        Dim context As New HttpContextWrapper(HttpContext.Current)
        _service = DomainServicesFactory.CreateDomainService(context)
        wwDataBinder1.Unbind()
        _service.InsertClientStatus(Client_ID.Value, _data)

        _data = New ClientStatus()
        lvlMsg.Text = "* Status information was saved successfully!"
        Page.DataBind()
    End Sub

    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        Dim context As New HttpContextWrapper(HttpContext.Current)
        _service = DomainServicesFactory.CreateDomainService(context)
        If (e.CommandName = "Edit1") Then
            _data = _service.GetClientStatus(e.CommandArgument)
            wwDataBinder1.DataBind()
        ElseIf (e.CommandName = "Remove1") Then
            If (_service.DeleteClientStatus(e.CommandArgument)) Then
                lvlMsg.Text = "* Status information was deleted successfully!"
            Else
                lvlMsg.Text = "* Status information was not deleted successfully!"
            End If
        End If

    End Sub
End Class